package com.PAT.UnSatisfying;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: zjz
 * @Date: 2021/12/23/23:34
 * @Description:排序,分类比较多的排序
 * @Target: 差9
 */
public class 德才论 {
    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);
        String s1 = in.nextLine();
        String[] s = s1.split(" ");
        int N = Integer.valueOf(s[0]); // 考生总数
        int L = Integer.valueOf(s[1]); // 录取最低分数线
        int H = Integer.valueOf(s[2]); // 优先录取线
        // H才德全尽，，德才总分排序
        ArrayList<DeCaiStudent> list1 = new ArrayList();

        // H德胜才，才分不到，德分到，总分排序
        ArrayList<DeCaiStudent> list2 = new ArrayList();

        // 低于H高于L，德分不低于才分，属于“才德兼亡”但尚有“德胜才”者，按总分排序
        ArrayList<DeCaiStudent> list3 = new ArrayList();

        // 高于L，总分排序
        ArrayList<DeCaiStudent> list4 = new ArrayList();
        int count =0; // 记人数

        DeCaiStudent[] students = new DeCaiStudent[N];
        for (int i = 0; i < N; i++) {
            String tempString = in.nextLine();
            String[] s2 = tempString.split(" ");
            DeCaiStudent  deCaiStudent = new DeCaiStudent(Integer.valueOf(s2[0]),Integer.valueOf(s2[1]),Integer.valueOf(s2[2]),Integer.valueOf(s2[1])+Integer.valueOf(s2[2]));
            students[i] = deCaiStudent;

        }

        Arrays.sort(students,new MyComparaByDeCai());

        for (DeCaiStudent student : students) {
            if (student.de>=H&&student.cai>=H){
                list1.add(student);
                count++;
            }else if (student.de>=H&&(student.cai>=L&&student.cai<H)){
                list2.add(student);
                count++;
            }else if (student.de>student.cai&&(student.de<H&&student.de>=L&&student.cai<H&&student.cai>=L)){
                list3.add(student);
                count++;
            }else if (student.de>=L&&student.cai>=L){
                list4.add(student);
                count++;
            }
        }


        System.out.println(count);
        if (list1.size()>0){
            for (DeCaiStudent o : list1) {
                System.out.println(o.id+" "+o.de+" "+o.cai);
            }
        }
        if (list2.size()>0){
            for (DeCaiStudent o : list2) {
                System.out.println(o.id+" "+o.de+" "+o.cai);
            }
        }
        if (list3.size()>0){
            for (DeCaiStudent o : list3) {
                System.out.println(o.id+" "+o.de+" "+o.cai);
            }
        }
        if (list4.size()>0){
            for (DeCaiStudent o : list4) {
                System.out.println(o.id+" "+o.de+" "+o.cai);
            }
        }

    }


    static class MyComparaByDeCai implements Comparator<DeCaiStudent>{
        @Override
        public int compare(DeCaiStudent o1, DeCaiStudent o2) {
            if (o1.sum==o2.sum){
                if (o1.de==o2.de){
                    return (int)(o1.id-o2.id);
                }else {
                    return -(o1.de-o2.de);
                }

            }else {
                return -(o1.sum-o2.sum);
            }
        }
    }


    // 对象是学生，有学号，两个分数
    static class DeCaiStudent{
        private long id;
        private int de;
        private int cai;
        private int sum;

        @Override
        public String toString() {
            return "DeCaiStudent{" +
                    "id=" + id +
                    ", de=" + de +
                    ", cai=" + cai +
                    ", sum=" + sum +
                    '}';
        }

        public int getSum() {
            return sum;
        }

        public void setSum(int sum) {
            this.sum = sum;
        }

        public DeCaiStudent() {
        }

        public DeCaiStudent(long id, int de, int cai, int sum) {
            this.id = id;
            this.de = de;
            this.cai = cai;
            this.sum = sum;
        }

        public long getId() {
            return id;
        }

        public void setId(long id) {
            this.id = id;
        }

        public int getDe() {
            return de;
        }

        public void setDe(int de) {
            this.de = de;
        }

        public int getCai() {
            return cai;
        }

        public void setCai(int cai) {
            this.cai = cai;
        }
    }
}
